<?php
	require '../ini.php';
	require '../../classes/xl_bai_viet.php';
	require '../../classes/xl_loai_bai_viet.php';
	
	#Khoi tao doi tuong
	$dt_xl_bai_viet = new xl_bai_viet;
	$dt_xl_loai_bai_viet = new xl_loai_bai_viet;
	
	#Kiem tra co ton tai ma hay khong
	if(empty($_GET['ma'])){
		$_SESSION['msg'] = 'Dữ liệu không hợp lệ !!!';
		$_SESSION['type_msg'] = 'error';
		header('Location: danh_sach.php');
		exit;
	}
	
	#Doc mot dong trong bang bai_viet trong CSDL
	$ma = $_GET['ma'];
	$bai_viet = $dt_xl_bai_viet->xem($ma);
	
	#Kiem tra ma co trong CSDL hay khong
	if($bai_viet == NULL){
		$_SESSION['msg'] = 'Mã không tồn tại!!!';
		$_SESSION['type_msg'] = 'error';
		header('Location: danh_sach.php');
		exit;
	}


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
 
	<head>
		
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		
		<title>Bài viết [Cập nhật]</title>
		
		<!--                       CSS                       -->
	  
		<!-- Reset Stylesheet -->
		<link rel="stylesheet" href="../skins/sa/resources/css/reset.css" type="text/css" media="screen" />
	  
		<!-- Main Stylesheet -->
		<link rel="stylesheet" href="../skins/sa/resources/css/style.css" type="text/css" media="screen" />
		
		<!-- Invalid Stylesheet. This makes stuff look pretty. Remove it if you want the CSS completely valid -->
		<link rel="stylesheet" href="../skins/sa/resources/css/invalid.css" type="text/css" media="screen" />	
		
		<!-- Colour Schemes
	  
		Default colour scheme is green. Uncomment prefered stylesheet to use it.
		
		<link rel="stylesheet" href="../skins/sa/resources/css/blue.css" type="text/css" media="screen" />
		
		<link rel="stylesheet" href="../skins/sa/resources/css/red.css" type="text/css" media="screen" />  
	 
		-->
		
		<!-- Internet Explorer Fixes Stylesheet -->
		
		<!--[if lte IE 7]>
			<link rel="stylesheet" href="../skins/sa/resources/css/ie.css" type="text/css" media="screen" />
		<![endif]-->
		
		<!--                       Javascripts                       -->
  
		<!-- jQuery -->
		<script type="text/javascript" src="../skins/sa/resources/scripts/jquery-1.3.2.min.js"></script>
		
		<!-- jQuery Configuration -->
		<script type="text/javascript" src="../skins/sa/resources/scripts/simpla.jquery.configuration.js"></script>
		
		<!-- Facebox jQuery Plugin -->
		<script type="text/javascript" src="../skins/sa/resources/scripts/facebox.js"></script>
		
		<!-- jQuery WYSIWYG Plugin -->
		<script type="text/javascript" src="../skins/sa/resources/scripts/jquery.wysiwyg.js"></script>
        
        <!-- jQuery CKEDITOR -->
		<script type="text/javascript" src="../includes/ckeditor/ckeditor.js"></script>
		
		<!-- Internet Explorer .png-fix -->
		
		<!--[if IE 6]>
			<script type="text/javascript" src="../skins/sa/resources/scripts/DD_belatedPNG_0.0.7a.js"></script>
			<script type="text/javascript">
				DD_belatedPNG.fix('.png_bg, img, li');
			</script>
		<![endif]-->
        
        <script type="text/javascript">
		
		function kiem_tra(){
			//Khi có form thì ta sử dụng document.tên form.tên điều khiển
			//VD: document.fthem.ma_sua.value
			/*
			if(document.getElementById('ma_sua').value == ''){
				alert('Bạn chưa nhập mã sữa, vui lòng kiểm tra lại!!!');
				document.getElementById('ma_sua').focus();
				return false;
			}
			*/
			var f = document.fcap_nhat;
			if(f.ma_nguoi_dung.value == ''){
				alert('Bạn chưa nhập mã người dùng, vui lòng kiểm tra lại!!!');
				f.ma_nguoi_dung.focus();
				return false;
			}
			
			if(f.tieu_de.value == ''){
				alert('Bạn chưa nhập tiêu đề, vui lòng kiểm tra lại!!!');
				f.tieu_de.focus();
				return false;
			}
			
			if(f.ngay_tao.value == ''){
				alert('Bạn chưa nhập ngày tạo, vui lòng kiểm tra lại!!!');
				f.ngay_tao.focus();
				return false;
			}
			
		}
		
		</script>
        
        <?php include '../js/jquery.php'; ?>
		
	</head>
  
	<body><div id="body-wrapper"> <!-- Wrapper for the radial gradient background -->
		
		<?php include '../widgets/sidebar.php' ?> <!-- End #sidebar -->
		
		<div id="main-content"> <!-- Main Content Section with everything -->
			
			<?php include '../widgets/noscript.php'; ?>
			
			<!-- Page Head -->
			
		  <!-- End .shortcut-buttons-set -->
			
			<div class="clear"></div> <!-- End .clear -->
			
			<div class="content-box"><!-- Start Content Box -->
				
				<div class="content-box-header">
					
					<h3>Bài viết [Cập nhật]</h3>
					
					<ul class="content-box-tabs">
						<li><a href="danh_sach.php">Danh sách</a></li> <!-- href must be unique and match the id of target div -->
						<li><a class="default-tab">Cập nhật</a></li>
					</ul>
					
					<div class="clear"></div>
					
				</div> <!-- End .content-box-header -->
				
				<div class="content-box-content">
					
					<div class="tab-content default-tab" id="tab2">
                    
                    <?php include '../widgets/thong_bao.php'; ?>
					
						<form action="cap_nhat_sm.php" method="post" id="fcap_nhat" name="fcap_nhat">
                        <input type="hidden" name="ma" value="<?php echo $bai_viet['ma']?>"/>
							
							<fieldset> <!-- Set class to "column-left" or "column-right" on fieldsets to divide the form into columns -->
								
                                <table>
                                	<tr>
                                    	<td><label>Loại bài viết:</label></td>
                                        <td>
                                            <select name="ma_loai_bai_viet">
                                            <option value="0">--No parent--</option>
												<?php 
                                                    $ds_loai_bai_viet_all = $dt_xl_loai_bai_viet->danh_sach_all();
                                                    foreach($ds_loai_bai_viet_all as $loai_bai_viet) {
                                                        if ($loai_bai_viet['ma'] == $_SESSION['ma_loai_bai_viet']) {
                                                            unset($_SESSION['ma_loai_bai_viet']);
                                                            $chon = 'selected';
                                                        } else {
                                                            $chon = '';
                                                        }
                                                        
                                                ?>
                                                <option <?php echo $chon ?> value="<?php echo $loai_bai_viet['ma'] ?>"><?php echo $loai_bai_viet['ten'] ?></option>
                                                <?php 
                                                    }
                                                ?>
                                            </select>
                                    	</td>
                                     <tr>
                                     	<td><label>Mã người dùng:</label></td>
                                        <td><input class="text-input medium-input" type="text" id="ma_nguoi_dung" name="ma_nguoi_dung" 
                                        	value="<?php echo $bai_viet['ma_nguoi_dung']?>"/></td>
                                     </tr>
                                     <tr>
                                     	<td><label>Tiêu đề:</label></td>
                                        <td><input class="text-input medium-input" type="text" id="tieu_de" name="tieu_de"
                                        	value="<?php echo $bai_viet['tieu_de']?>" /></td>
                                     </tr>
                                     <tr>
                                     	<td style="vertical-align:middle"><label>Nội dung tóm tắt:</label></td>
                                        <td>
                                        <textarea class="text-input textarea" id="noi_dung_tom_tat" name="noi_dung_tom_tat" rows="15"><?php echo $bai_viet['noi_dung_tom_tat']?></textarea>
                                        <script type="text/javascript">
											CKEDITOR.replace('noi_dung_tom_tat'); 
                                        </script>
                                        </td>
                                     </tr>
                                      <tr>
                                     	<td style="vertical-align:middle"><label>Nội dung chi tiết:</label></td>
                                        <td><textarea class="text-input textarea" id="noi_dung_chi_tiet" name="noi_dung_chi_tiet" cols="80" rows="15"><?php echo $bai_viet['noi_dung_chi_tiet']?></textarea>
                                        <script type="text/javascript">
											CKEDITOR.replace('noi_dung_chi_tiet'); 
                                        </script>
                                        </td>
                                     </tr>
                                      <tr>
                                     	<td><label>Ngày tạo:</label></td>
                                        <td>
                                        <input class="text-input medium-input" type="text" id="ngay_tao" name="ngay_tao" value="<?php echo $bai_viet['ngay_tao']?>" /> 
                                        <script>
											$(function() {
												
												$( "#ngay_tao" ).datepicker({
													dateFormat: "dd/mm/yy",
													changeMonth: true,
													changeYear: true,
													showOn: "button",
													buttonImage: "../images/calendar.gif",
													buttonImageOnly: true,
													showAnim: "bounce"
												});
												$( "#ngay_tao" ).datepicker( $.datepicker.regional[ "vi" ] );
												
											});
										</script>
                                        </td>
                                     </tr>
                                     <tr>
                                     	<td><label>Số lần xem:</label></td>
                                        <td><input class="text-input medium-input" type="text" id="so_lan_xem" name="so_lan_xem"
                                        	value="<?php echo $bai_viet['so_lan_xem']?>" /></td>
                                     </tr>
                                     <tr>
                                     	<td><label>Trạng thái:</label></td>
                                        <td>
                                            <label><input type="radio" name="trang_thai" value="1" checked="checked" /> Hiển thị<br />
                                           <input type="radio" name="trang_thai" value="0" /> Không hiển thị</label>
                                        </td>
                                     </tr>
                                     <tr>
                                     	<td><label>Hình:</label></td>
                                        <td><input type="file" id="hinh" name="hinh" /><br />
                                        	<img src="../../upload/bai_viet/<?php echo $bai_viet['hinh']; ?>" width="100" height="100" /><br />
											(*.gif , *.jpg ,*.png < 2000kb)
										</td>
                                     </tr>
                                     <tr>
                                     	<td colspan="2" style="padding-left:350px">
                                        	<input class="button" name="bt_luu_thoat" type="submit" value="Lưu và thoát" onclick="return kiem_tra()" />
                                            <input class="button" name="bt_luu_tieptuc" type="submit" value="Lưu và tiếp tục" onclick="return kiem_tra()" />
                                            <input class="button" name="bt_quay_ve" type="button" value="Quay về" onclick="window.location.href = 'danh_sach.php'" />
                                        </td>
                                     </tr>
								</table>
								
							</fieldset>
							
							<div class="clear"></div><!-- End .clear -->
							
						</form>
						
					</div> <!-- End #tab2 -->        
					
				</div> <!-- End .content-box-content -->
				
			</div> <!-- End .content-box -->
			
			
			<div class="clear"></div>
			
			
			<?php include '../widgets/footer.php'; ?><!-- End #footer -->
			
		</div> <!-- End #main-content -->
		
	</div></body>
  
</html>
<?php
	$dt_xl_bai_viet->disconnect();
?>
